| 1 |  |  | import { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |   Hooks | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | } from '../../' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | * Get All attributes from a Abe tag | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | * @return {Object} parsed attributes | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | export function getAll(str, json) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |   str = Hooks.instance.trigger('beforeAbeAttributes', str, json) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |   //This regex analyzes all attributes of a Abe tag  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |   var re = /\b([a-z][a-z0-9\-]*)\s*=\s*("([^"]+)"|'([^']+)'|(\S+))/ig | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |    | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |   var attrs = { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |     autocomplete: null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |     desc: '', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     display: null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     editable: true, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     key: '', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |     'max-length': null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     'min-length': 0, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     order: 0, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     prefill: false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     'prefill-quantity': null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     reload: false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     required: false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     source: null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     tab: 'default', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     type: 'text', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     value: '', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     file: '', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     visible: true | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |   } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |    | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |   for (var match; match = re.exec(str); ){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     attrs[match[1]] = match[3] || match[4] || match[5] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |   } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |   attrs.sourceString = attrs.source | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |   attrs.source = (attrs.source)?  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |     ((json != null && json['abe_source'] != null)?  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |       json['abe_source'][attrs.key] :  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |       null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |     ) :  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |     null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |   attrs.editable = (attrs.editable) ? true : false | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |   attrs = Hooks.instance.trigger('afterAbeAttributes', attrs, str, json) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |   return attrs | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  | } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 53 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 54 |  |  | export function sanitizeSourceAttribute(obj, jsonPage){ | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                        
            
                                    
            
            
                | 55 |  |  |   if(obj.sourceString != null && obj.sourceString.indexOf('{{') > -1) { | 
            
                                                        
            
                                    
            
            
                | 56 |  |  |     var matches = obj.sourceString.match(/({{[a-zA-Z._]+}})/g) | 
            
                                                        
            
                                    
            
            
                | 57 |  |  |     if(matches !== null) { | 
            
                                                        
            
                                    
            
            
                | 58 |  |  |       Array.prototype.forEach.call(matches, (match) => { | 
            
                                                        
            
                                    
            
            
                | 59 |  |  |         var val = match.replace('{{', '') | 
            
                                                        
            
                                    
            
            
                | 60 |  |  |         val = val.replace('}}', '') | 
            
                                                        
            
                                    
            
            
                | 61 |  |  |          | 
            
                                                        
            
                                    
            
            
                | 62 |  |  |         try { | 
            
                                                        
            
                                    
            
            
                | 63 |  |  |           val = eval('jsonPage.' + val) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                        
            
                                    
            
            
                | 64 |  |  |         }catch(e) { | 
            
                                                        
            
                                    
            
            
                | 65 |  |  |           val = '' | 
            
                                                        
            
                                    
            
            
                | 66 |  |  |         } | 
            
                                                        
            
                                    
            
            
                | 67 |  |  |         obj.sourceString = obj.sourceString.replace(match, val) | 
            
                                                        
            
                                    
            
            
                | 68 |  |  |       }) | 
            
                                                        
            
                                    
            
            
                | 69 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 70 |  |  |   } | 
            
                                                        
            
                                    
            
            
                | 71 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 72 |  |  |   return obj | 
            
                                                        
            
                                    
            
            
                | 73 |  |  | } | 
            
                        
This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.